<?php
$username=$_GET["username"];
$pwd=$_GET["pwd"];
$username = trim($_GET['username']);
$pwd = trim($_GET['pwd']);
if(!$username||!$pwd){
    echo json_encode(
        [
            "type" => "error",
            "msg" => "参数不足",  
        ]
    );
}

require("./connect.php");

$sql="SELECT * FROM `user` WHERE `username`='$username'";
$res=mysqli_query($con,$sql);
if(!$res){
  
    echo json_encode(
        [
            "type" => "error",
            "msg" => "数据库错误",  
            "detail"=>"'mysqli_error($con) '"
        ]
    );
}
$arr=mysqli_fetch_all($res,MYSQLI_ASSOC);

$time1=$arr[0]["time"];

// if($time1>=3){
    
//     echo json_encode(
//         [
//             "type" => "error",
//             "msg" => "今日登录失败次数到上限jjjj",  
//         ]
//     ); 
// }

if($arr[0]['pwd']===$pwd){
    if($time1>=3){
    
    echo json_encode(
        [
            "code" => 2,
            "msg" => "今日登录失败次数到上限",  
        ]
    ); 
}
    else echo json_encode(
        [
            "code" => 0,
            "msg" => "登录成功",  
        ]
    );
}
else if($arr[0]['pwd']!==$pwd){
   $time1++;
    $sql2="UPDATE `user` SET `time`='$time1' WHERE`username`='$username' ";
  
    $res2=mysqli_query($con,$sql2); 
    if($time1>=3){
    
        echo json_encode(
            [
                "code" => 2,
                "msg" => "今日登录失败次数到上限",  
                "count"=>$time1

            ]
        ); 
    }
    else echo json_encode(
        [   
            // "ss"=>$arr,
            "code" => 1,
            "msg" => "登录失败",  
            "count"=>$time1
        ]
    );
}
mysqli_close($con);
